package org.xy.vte.velocity;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.xy.vte.bean.TableVO;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

/**
 * @Classname VelocityContext
 * @Description TODO
 * @Date 2024/6/24 15:07
 * @Created by jinxiaoyao
 */
public class Context {
    // 模版引擎

    VelocityEngine velocityEngine;
    private TableVO tableVO;

    public Context(TableVO tableVO) {
        this.tableVO = tableVO;
        velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();
    }

    public void entity() {

        // 载入（获取）模板对象
        Template t = velocityEngine.getTemplate("template/entity/entity.java.vm");
        VelocityContext ctx = new VelocityContext();
        // entity的包路径
        ctx.put("package", "org.xy.vte.test.gen" + ".entity");
        ctx.put("tableName", tableVO.getTableName());
        ctx.put("tableClassName", "tableClassName");
        ctx.put("columns", tableVO.getColumns());
        StringWriter sw = new StringWriter();
        t.merge(ctx, sw);
        System.out.println(sw.toString());
    }

}
